<template>
	<div style="padding: 12px; box-sizing: border-box">
		<component :is="components[tableRel[0].value]" ref="table" :editData="tableData" :key="theKey" @getTableData="getTableData"></component>
		<!-- <ElderReliefApply ref="table" :editData="tableData" :key="theKey" @getTableData="getTableData"></ElderReliefApply> -->
	</div>
</template>

<script setup lang="ts">
import { ref, reactive } from 'vue'
import apiMod from '@/apiMod/index'
import { getStore } from '@/utils/store'
import {components} from '@/views/instOperate/components/ApplyReport/components/config'

const emit = defineEmits(['backData'])
let props = withDefaults(
	defineProps<{
		nowRowData?: any
	}>(),
	{
		nowRowData: {},
	}
)
let table = ref()
let theKey = ref(0)
let orgData = reactive({})
let tableData = reactive({})
const getOrgData = () => {
	let orgInfo = getStore('organizationInfo')
	// 获取表格固定信息
	let date = props.nowRowData.belongDate.split('-')
	let params = {
		year: date[0],
		month: date[1],
		creditCode: orgInfo.creditCode,
		projectId: props.nowRowData.subsidyProjectId,
	}
	apiMod.view_application_subsidy_org_base_info(params).then((res) => {
		orgData = { ...res.data.organizationInfoPO, ...res.data.staffPO }
		orgData['belongDate'] = props.nowRowData.belongDate

		if (props.nowRowData.tableData&&props.nowRowData.tableData.creditCode) {
			tableData = props.nowRowData.tableData
			tableData['belongDate'] = props.nowRowData.belongDate
		} else {
			tableData = {
				subsidyType: props.nowRowData.subsidyType,
				belongDate: props.nowRowData.belongDate,
				...orgData,
			}
		}
		theKey.value = Math.random()
	})
}

watch(()=>props.nowRowData.belongDate,(val)=>{
	if(val){
		getOrgData()
	}
},{
	immediate:true,
	deep:true
})
let tableRel:any = ref([])
watch(()=>props.nowRowData.tableRel,(val)=>{
	if(val){
		tableRel.value = JSON.parse(val)
	}
},{
	immediate:true,
	deep:true
})

const getTableData = (data) => {
	emit('backData', {
		...props.nowRowData,
		tableData: data,
	})
}

const getBackData = () =>{
  table.value.backData()
}
defineExpose({getBackData})
</script>
<style scoped lang="scss">
.fr_str {
	display: flex;
	flex-direction: row;
	justify-content: flex-start;
	align-items: center;
}
.add_part {
}
</style>
